package com.toe.user.webapi.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.toe.pojo.dto.user.UserBusinessRoleAddDTO;
import com.toe.pojo.entity.user.UserBusinessRole;
import com.toe.pojo.vo.user.UserBusinessRoleVO;
import com.toe.user.service.UserBusinessRoleService;
import com.toe.user.service.UserBusinessService;
import com.toe.user.webapi.mapper.UserBusinessRoleMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@Service
@Slf4j
public class UserBusinessRoleServiceImpl extends ServiceImpl<UserBusinessRoleMapper, UserBusinessRole> implements UserBusinessRoleService {

    @Autowired
    private UserBusinessRoleMapper userBusinessRoleMapper;

    @Override
    public void insert(UserBusinessRoleAddDTO userBusinessRoleAddDTO) {
        UserBusinessRole userBusinessRole = new UserBusinessRole();
        BeanUtils.copyProperties(userBusinessRoleAddDTO,userBusinessRole);
        LocalDateTime now = LocalDateTime.now();
        userBusinessRole.setCreateTime(now);
        userBusinessRole.setUpdateTime(now);
        userBusinessRoleMapper.insert(userBusinessRole);
    }

    @Override
    public void delete(long id) {
        userBusinessRoleMapper.deleteById(id);
    }

    @Override
    public List<UserBusinessRoleVO> selectAllAdminRole() {
        List<UserBusinessRoleVO> userBusinessRoleVOS = userBusinessRoleMapper.selectAllBusinessRole();
        return userBusinessRoleVOS;
    }

    @Override
    public Boolean selectOneAdminRole(long adminId, long roleId) {
        UserBusinessRoleVO userBusinessRole = userBusinessRoleMapper.selectOneBusinessRole(adminId, roleId);
        if (userBusinessRole==null)
            return false;
        return true;
    }

    @Override
    public void deleteOne(long adminId, long roleId) {
        userBusinessRoleMapper.deleteOne(adminId, roleId);
    }
}
